package org.csu.mypetstore.api.controller.front;

import org.csu.mypetstore.api.common.CommonResponse;
import org.csu.mypetstore.api.service.OrderService;
import org.csu.mypetstore.api.vo.ItemVO;
import org.csu.mypetstore.api.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
//@RequestMapping("/order/")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/account/users/{userId}/orders")
    @ResponseBody
    public CommonResponse<List<OrderVO>> getOrdersByUserId(@PathVariable("userId") String userId) {
        return orderService.getOrdersByUserId(userId);
    }

    @GetMapping("/order/orders/{id}")
    @ResponseBody
    public CommonResponse<OrderVO> getOrdersByOrderId(@PathVariable("id") String orderId) {
        return orderService.getOrdersByOrderId(orderId);
    }

    @PostMapping("/order/")
    @ResponseBody
    public CommonResponse<OrderVO> addOrder(@RequestBody OrderVO orderVO){
        return orderService.addOrder(orderVO);
    }

}
